/*河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
*/
package cn.javaxc.system.action.base;
import java.io.*;
import java.util.*;
import java.sql.*;
import cn.javaxc.model.base.SQL;
import cn.javaxc.model.base.SQLList;
import cn.javaxc.model.base.SQLMap;
import cn.javaxc.model.base.SQLParam;
import cn.javaxc.model.page.BatisPage;
import cn.javaxc.mvcwork.controller.web.TreeBean;
import cn.javaxc.mvcwork.util.common.CommonUtil;
import cn.javaxc.mvcwork.util.common.MapListUtil;
import cn.javaxc.mvcwork.util.helper.FrameHelper;
import cn.javaxc.mvcwork.util.helper.TreeTableHelper;
import org.springframework.beans.factory.annotation.Autowired;
import cn.javaxc.system.action.base.BaseAction;
import cn.javaxc.mvcwork.util.common.*;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.util.HtmlUtils;
import cn.javaxc.mvcwork.controller.AppUtils;
import cn.javaxc.talent.util.common.*;
import cn.javaxc.system.mapper.base.BaseMapper;
public class BaseAction extends BatisPage
{
    @Autowired(required=false)
	private BaseMapper mapper;
    
    public WorkTime workTime=new WorkTime();
    /**
    时间计算
    */
    public Timestamp getAfterWorkHour(Object time,Object hour,SQLMap emt){
        workTime.createPage(this);
        return new FrameHelper(workTime).getAfterWorkHour(time,hour,emt.getMap());
    }
    /**
    时间计算
    */
    public Timestamp getAfterWorkHour(Object time,Object hour,String station_type,String org_id){
        SQLMap emt=new SQLMap();
        emt.setProperty("station_type",station_type);
        emt.setProperty("org_id",org_id);
        return getAfterWorkHour(time,hour,emt);
    }
    
    
    /**
    * 发送短信
    */
    public String sendSMS(String nums,String message){
        return SMSMessage.sendSMS(nums,message);
    }
    
    
    public SQLMap create_code(Object code_type,String barname){
        SQLMap m=create_scode(code_type);
        m.put(barname,m.get("bar"));
        return m;
    }
    
    
    protected Map<String, Object> getRequestData(HttpServletRequest request)
    {
        Map<String, Object> mapn = new HashMap();
        Map<String, String[]> map = request.getParameterMap();
        for (Map.Entry<String, String[]> entry : map.entrySet()) {
            String value = org.apache.commons.lang.StringUtils.join((String[])entry.getValue(), ",");
            String nvalue = HtmlUtils.htmlEscape(value);
            mapn.put((String)entry.getKey(), nvalue);
        }
        return mapn;
    }
    
    /**
    */
    
    private SQLMap create_scode(Object code_type) {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        params.put("code_type",code_type);
        SQLList<SQLMap> s_ecode=mapper.s_ecode(params);
        SQLMap s_ecode_emt=s_ecode.getExistfirst();
        result.put("s_ecode", s_ecode_emt);
        
        return s_ecode_emt;
    }
    /**
    */
    
    public SQLMap create_emtcode(Object code_type) {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        SQLList<SQLMap> s_ecode=mapper.s_ecode(params);
        SQLMap s_ecode_emt=s_ecode.getExistfirst();
        result.put("s_ecode", s_ecode_emt);
        
        return s_ecode_emt;
    }
    /**
    基类
    */
    
    public Map listDepartments() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        TreeBean tb;
        
        Object dept_id =mapper.dept_id(params);
        result.put("dept_id", dept_id);
        
        
        result.put("CMID6", dept_id);
        
        
        tb = createTreeBean(BaseAction.class,"l_firm_treecols");
        tb.setPrefix("img");
        tb.setPid(dept_id);
        tb.setPrefix("list");
        SQLList<SQLMap> l_firm=mapper.l_firm(params);
        l_firm = l_firm.buildTree(tb,tb.getPid());
        result.put("l_firm", l_firm);
        
        
        params.def("CMID7",-1);
        params.def("CMID8",-1);
        SQLList<SQLMap> s_s=mapper.s_s(params);
        SQLMap s_s_emt=s_s.getExistfirst();
        result.put("s_s", s_s_emt);
        
        
        
        
        
        
        
        
        
        
        params.def("CMID7",-1);
        SQLList<SQLMap> s_person=mapper.s_person(params);
        s_person.setSelectNone("全部");
        result.put("s_person", s_person);
        
        
        
        
        params.def("CMID7",-1);
        Object s_son_firm =mapper.s_son_firm(params);
        result.put("s_son_firm", s_son_firm);
        
        return result;
    }
    /**
    */
    
    public String getSysList(String table) {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        
        return getSystemStatus().getSysList(getParameter(table));
    }
    /**
    */
    
    public SQLList s_question_db() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        TreeBean tb;
        
        tb = createTreeBean(BaseAction.class,"s_db_treecols");
        tb.setPrefix("img");
        tb.setPrefix("");
        SQLList<SQLMap> s_db=mapper.s_db(params);
        s_db = s_db.buildTree(tb,tb.getPid());
        result.put("s_db", s_db);
        
        return s_db;
    }
    /**
    发送邮件
    */
    
    public Map send_mail() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        SQLList<SQLMap> s_mail=mapper.s_mail(params);
        SQLMap s_mail_emt=s_mail.getExistfirst();
        result.put("s_mail", s_mail_emt);
        
        
        AppUtils.sendMail(s_mail_emt.getMap(),getParameter("subject"),getParameter("message"), (String)StringUtils.isEmpty(getParameter("file_item_ids"),"-1"),getParameter("replyMails"));
        
        return result;
    }
    /**
    插入邮件发送记录
    */
    
    public Object insert_mail(String link_module_id,Object link_item_id) {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        params.put("link_module_id",link_module_id);
        params.put("link_item_id",link_item_id);
        int CMIDmail_id = mapper.CMIDmail_id(params);
        result.put("CMIDmail_id", CMIDmail_id);
        
        
        for (SQLMap emt:SQL.foreach(getParameter("file_item_ids"),"file_item_id",",")){
            params=new SQLParam(request,emt.getMap());
            if(SQL.isNotNull(params.get("file_item_id")))
            mapper.insert_mail_attach(params);
        }
        
        
        for (SQLMap emt:SQL.foreach(getParameter("replyMails"),"sendto","\n")){
            params=new SQLParam(request,emt.getMap());
            if(SQL.isNotNull(params.get("sendto")))
            mapper.insert_mail_recipient(params);
        }
        
        return result;
    }
    /**
    合并模板单页显示
    */
    
    public String buildTemplate(SQLList<SQLMap> l_record_work) {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        StringBuffer buf=new StringBuffer();
        for (SQLMap emt:l_record_work ){
            buf.append(TemplateUtil.buildTemplate(emt,new SQLList(),""));
        }
        
        return buf.toString();
    }
    /**
    合并记录单页显示
    */
    
    public String buildTemplateRecord(SQLList<SQLMap> l_record_work)  {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        StringBuffer buf=new StringBuffer();
        for (SQLMap emt:l_record_work ){
            
            
            result.put("record_work_id", emt.get("record_work_id"));
            
            
            SQLList<SQLMap> s_record_work=mapper.s_record_work(params);
            SQLMap s_record_work_emt=s_record_work.getExistfirst();
            result.put("s_record_work", s_record_work_emt);
            
            
            SQLList<SQLMap> record=mapper.record(params);
            result.put("record", record);
            
            
            buf.append(TemplateUtil.buildTemplate(s_record_work_emt,record,".detail"));
        }
        
        return buf.toString();
    }
    /**
    执行下一步，状态跳转
    */
    
    public Map u_nextstep() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        mapper.u_nextstep(params);
        
        
        
        return result;
    }
    /**
    */
    
    public Map d_client() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        mapper.d_client(params);
        
        return result;
    }
    /**
    */
    
    public Map d_folders() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        mapper.d_folders(params);
        
        return result;
    }
    /**
    */
    
    public Map d_files() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        mapper.d_files(params);
        
        return result;
    }
    /**
    */
    
    public Map d_link() {
        
        Map result=new HashMap();
        SQLParam params=new SQLParam(request,result);
        
        mapper.d_link(params);
        
        return result;
    }
}